package utils

import (
	"fmt"
	"time"

	"github.com/robfig/cron"
)

/**
	定时获取任务
	默认配置:
		disk:半天推一次数据
		mem ,cpu 2 分钟一次
 */

func demo() {
	fmt.Println("demo")
}

func CronSetUp(a func(), s string) {

	c := cron.New()

	//c.AddFunc("*/20 * * * * *", func() {
	//	a()
	//
	//})

	c.AddFunc(fmt.Sprintf("%s", s), func() {
		a()

	})

	c.Start()

	t1 := time.NewTimer(time.Second * 10)
	for {
		select {
		case <-t1.C:
			t1.Reset(time.Second * 10)
		}
	}
}

func main() {
	CronSetUp(demo,"")
}
